package svc

import (
	"context"
	bannersrvClient "gozero-microservices/common-service/rpc/client/bannersrv"
	navsrvClient "gozero-microservices/common-service/rpc/client/navsrv"
	regionsrvClient "gozero-microservices/common-service/rpc/client/regionsrv"
	"gozero-microservices/gateway-api/internal/config"
	inventorysrvClient "gozero-microservices/inventory-service/rpc/client/inventorysrv"
	ordersrvClient "gozero-microservices/order-service/rpc/client/ordersrv"
	"gozero-microservices/user-service/rpc/userdeliveryaddrsrv"
	"gozero-microservices/user-service/rpc/usersrv"

	"github.com/zeromicro/go-zero/core/logx"
	"github.com/zeromicro/go-zero/zrpc"
)

type ServiceContext struct {
	Config config.Config
	Logger logx.Logger

	// user rpc service[使用服务分散的方式: 多个proto文件多个服务]
	UserSrv             usersrv.UserSrv
	UserDeliveryAddrSrv userdeliveryaddrsrv.UserDeliveryAddrSrv

	// common rpc service[使用服务分组的方式: 一个proto文件多个服务]
	BannerSrv bannersrvClient.BannerSrv
	RegionSrv regionsrvClient.RegionSrv
	NavSrv    navsrvClient.NavSrv

	// order rpc service[使用服务分组的方式: 一个proto文件多个服务]
	OrderSrv ordersrvClient.OrderSrv

	// inventory rpc service[使用服务分组的方式: 一个proto文件多个服务]
	InventorySrv inventorysrvClient.InventorySrv
}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		Config: c,
		Logger: logx.WithContext(context.Background()),

		// 使用服务分散的方式
		UserSrv:             usersrv.NewUserSrv(zrpc.MustNewClient(c.UserRpc)),
		UserDeliveryAddrSrv: userdeliveryaddrsrv.NewUserDeliveryAddrSrv(zrpc.MustNewClient(c.UserRpc)),

		// 使用服务分组的方式
		BannerSrv: bannersrvClient.NewBannerSrv(zrpc.MustNewClient(c.CommonRpc)),
		RegionSrv: regionsrvClient.NewRegionSrv(zrpc.MustNewClient(c.CommonRpc)),
		NavSrv:    navsrvClient.NewNavSrv(zrpc.MustNewClient(c.CommonRpc)),

		// 使用服务分组的方式
		OrderSrv: ordersrvClient.NewOrderSrv(zrpc.MustNewClient(c.OrderRpc)),

		// 使用服务分组的方式
		InventorySrv: inventorysrvClient.NewInventorySrv(zrpc.MustNewClient(c.InventoryRpc)),
	}
}
